# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=cffi
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}" "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=1.11.5
pkgrel=1
pkgdesc="Foreign Function Interface for Python calling C code (mingw-w64)"
url='https://cffi.readthedocs.io/'
license=('MIT')
arch=('any')
makedepends=("${MINGW_PACKAGE_PREFIX}-python2-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python2-pycparser"
             "${MINGW_PACKAGE_PREFIX}-python3-pycparser")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python2-pytest-runner"
              "${MINGW_PACKAGE_PREFIX}-python3-pytest-runner")
_revision=486d919c0b87288ec93c7696f75e2105ed4a91fd
source=("${_realname}-${pkgver}.tar.gz::https://bitbucket.org/cffi/cffi/get/${_revision}.tar.gz")
sha256sums=('4e679ec73037b0cfa3b23f6ee4fbb278595b8ecfa6adc101e7b55e51e2a28812')

prepare() {
  cd ${srcdir}
  cp -r cffi-cffi-${_revision::12} python2-build-${CARCH}
  cp -r cffi-cffi-${_revision::12} python3-build-${CARCH}
}

build() {
  cd "${srcdir}"
  for pver in {2,3}; do  
    msg "Python ${pver} build for ${CARCH}"  
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done
}

package_python3-cffi() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3-pycparser")
  cd ${srcdir}/python3-build-${CARCH}
  ${MINGW_PREFIX}/bin/python3 setup.py build
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}"

  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}"/share/licenses/python3-${_realname}/LICENSE
}

package_python2-cffi() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2-pycparser")
  cd ${srcdir}/python2-build-${CARCH}
  ${MINGW_PREFIX}/bin/python2 setup.py build
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}"

  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}"/share/licenses/python2-${_realname}/LICENSE
}

package_mingw-w64-i686-python2-cffi() {
  package_python2-cffi
}

package_mingw-w64-i686-python3-cffi() {
  package_python3-cffi
}

package_mingw-w64-x86_64-python2-cffi() {
  package_python2-cffi
}

package_mingw-w64-x86_64-python3-cffi() {
  package_python3-cffi
}
